﻿#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QDebug>
#include <QDateTime>
#include  <string>

#pragma execution_character_set("utf-8")

#define RADIUS		200.0
#define MARGIN		20.0

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{

    ui->setupUi(this);
    initData();

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initData() {
    // AE List
    QStringList ae1 = {"AM0001", "CHING KAM FUNG, TONY", "HQ", "A"};
    QStringList ae2 = {"AM0002", "WALLACE TANG", "HQ", "A"};
    QStringList ae3 = {"AM0002", "JOHAN LEEG", "ID", "A"};
    QStringList ae4 = {"AM0002", "JOANSHIEN LEE", "IS", "A"};
    QStringList ae5 = {"AM0002", "HUI SUEN TAK", "A", "A"};
    QStringList ae6 = {"AM0002", "HUI SUEN TAK", "YY", "A"};
    QStringList ae7 = {"AM0002", "WALLACE TANG", "Developer", "A"};
    QStringList ae8 = {"AM0002", "XI NIU BEN BEN MOBILE APP CLIENT", "TRADE", "A"};
    QStringList ae9 = {"AM0002", "RSI HOUSE ACCOUNT", "RISk", "A"};
    QStringList ae10 = {"AM0032", "HOUSE A/C OF WEST BULL SEC LTD", "A", "A"};
    QStringList ae11 = {"AM004", "WALLACE TANG", "IS", "A"};
    QStringList ae12 = {"AM005", "WALLACE TANG", "A", "A"};
    QStringList ae13 = {"AM0062", "WALLACE TANG", "HW", "A"};
    QStringList ae14 = {"AM062", "RSI HOUSE ACCOUNT", "A", "A"};
    QStringList ae15 = {"AM0702", "WALLACE TANG", "A", "A"};
    QStringList ae16 = {"AM0082", "WALLACE TANG", "A", "A"};
    QStringList ae17 = {"AMee02", "HOUSE A/C OF WEST BULL SEC LTD", "A", "A"};
    QStringList ae18 = {"AM0tt02", "WALLACE TANG", "ggg", "A"};
    QStringList ae19 = {"AM06602", "LIU YANLIANZHIG", "sss", "A"};
    QStringList ae20 = {"AM6002", "WALLACE TANG", "CEO OFFICE", "A"};
    QStringList ae21 = {"AM0672", "HOUSE A/C OF WEST BULL SEC LTDG", "TRADE@@WWW", "A"};


    m_vecAEList.push_back(ae1);
    m_vecAEList.push_back(ae2);
    m_vecAEList.push_back(ae3);
    m_vecAEList.push_back(ae4);
    m_vecAEList.push_back(ae5);
    m_vecAEList.push_back(ae6);
    m_vecAEList.push_back(ae7);
    m_vecAEList.push_back(ae8);
    m_vecAEList.push_back(ae9);
    m_vecAEList.push_back(ae10);
    m_vecAEList.push_back(ae11);
    m_vecAEList.push_back(ae12);
    m_vecAEList.push_back(ae13);
    m_vecAEList.push_back(ae14);
    m_vecAEList.push_back(ae15);
    m_vecAEList.push_back(ae16);
    m_vecAEList.push_back(ae17);
    m_vecAEList.push_back(ae18);
    m_vecAEList.push_back(ae19);
    m_vecAEList.push_back(ae20);
    m_vecAEList.push_back(ae21);
    m_vecAEList.push_back(ae1);
    m_vecAEList.push_back(ae2);
    m_vecAEList.push_back(ae3);
    m_vecAEList.push_back(ae4);
    m_vecAEList.push_back(ae5);
    m_vecAEList.push_back(ae6);
    m_vecAEList.push_back(ae7);
    m_vecAEList.push_back(ae8);
    m_vecAEList.push_back(ae9);
    m_vecAEList.push_back(ae10);
    m_vecAEList.push_back(ae11);
    m_vecAEList.push_back(ae12);
    m_vecAEList.push_back(ae13);
    m_vecAEList.push_back(ae14);
    m_vecAEList.push_back(ae15);
    m_vecAEList.push_back(ae16);
    m_vecAEList.push_back(ae17);
    m_vecAEList.push_back(ae18);
    m_vecAEList.push_back(ae19);
    m_vecAEList.push_back(ae20);
    m_vecAEList.push_back(ae21);

     QStringList ol1 = {"PFull", "0.255", "1000000", "RSISMOB", "16:21:23", "0", "0"};
     QStringList ol2 = {"PFull", "0.255", "1000000", "RSISMOB", "16:21:23", "0", "0"};
     QStringList ol3 = {"PFull", "0.255", "1000000", "RSISMOB", "16:21:23", "0.255", "60000"};
     QStringList ol4 = {"PFull", "0.255", "1000000", "RSISMOB", "16:21:23", "0.255", "40000"};
    m_vecOrderLog.push_back(ol1);
    m_vecOrderLog.push_back(ol2);
    m_vecOrderLog.push_back(ol3);
    m_vecOrderLog.push_back(ol4);

    // OR2
    QStringList or1 = {"F180120","","HK:00980","WestBull02","20230415-HK-112","unknown","CAN","Bid","0.4800","1,000","0","0","Input=12:04:16,IS=12:04:17,Cancel=12:04:24,CS=12:04:25","N"};
    QStringList or2 = {"F180121","","HK:00004","WestBull02","20230415-HK-109","unknown","FEX","Ask","17.9000","2,000","2,000","0","Input=12:01:29,IS=12:01:30,Amend=12:02:00,AS=12:02:00,Amend=12:07:43,AF=12:07:44,PartiallyFilled=12:08:15,Filled=12:08:15","N"};
    QStringList or3 = {"F180127","","HK:00007","WestBull02","20230415-HK-12","unknown","CAN","Bid","0.1000","2,000","0","0","Input=09:05:14,IS=09:05:14,IE=09:20:26","N"};
    QStringList or4 = {"F180120","","HK:00980","WestBull02","20230415-HK-112","unknown","CAN","Bid","0.4800","1,000","0","0","Input=12:04:16,IS=12:04:17,Cancel=12:04:24,CS=12:04:25","N"};
    QStringList or5 = {"F180120","","HK:01288","WestBull02","20230415-HK-103","unknown","Q","Ask","3.0700","2,000","0","2,000","Input=11:44:56,IS=11:44:56,Amend=11:45:48,AS=11:45:49,Amend=11:47:25,AS=11:47:25,Amend=12:01:02,AS=12:01:03,Cancel=12:08:07,CF=12:08:08,Cancel=12:08:55,CF=12:08:55","N"};
    QStringList or6 = {"F180120","","HK:00980","WestBull02","20230415-HK-112","unknown","CAN","Bid","0.4800","1,000","0","0","Input=12:04:16,IS=12:04:17,Cancel=12:04:24,CS=12:04:25","N"};
    QStringList or7 = {"F180120","","HK:00980","WestBull02","20230415-HK-112","unknown","CAN","Bid","0.4800","1,000","0","0","Input=12:04:16,IS=12:04:17,Cancel=12:04:24,CS=12:04:25","N"};
    QStringList or8 = {"F180125","","HK:00007","WestBull02","20230415-HK-14","unknown","Q","Bid","0.1000","2,000","0","2,000","Input=09:16:28,IS=09:16:29,Amend=09:16:47,AF=09:16:47,Cancel=09:17:59,CF=09:18:00","N"};
    QStringList or9 = {"F180120","","HK:00980","WestBull02","20230415-HK-112","unknown","CAN","Bid","0.4800","1,000","0","0","Input=12:04:16,IS=12:04:17,Cancel=12:04:24,CS=12:04:25","N"};
    QStringList or10 = {"F180122","","HK:00002","WestBull02","20230415-HK-66","unknown","FEX","Ask","57.9000","1,000","1,000","0","Input=10:08:18,Filled=10:08:19","N"};
    m_vecOrderListOr2.push_back(or1);
    m_vecOrderListOr2.push_back(or2);
    m_vecOrderListOr2.push_back(or3);
    m_vecOrderListOr2.push_back(or4);
    m_vecOrderListOr2.push_back(or5);
    m_vecOrderListOr2.push_back(or6);
    m_vecOrderListOr2.push_back(or7);
    m_vecOrderListOr2.push_back(or8);
    m_vecOrderListOr2.push_back(or9);
    m_vecOrderListOr2.push_back(or10);

    QStringList fol1 = {"","C0000208 zhaoxuchang","20230712-HK-5","N","Xyy1","16:22:01","Ask","HK:01288","2.600","1,000.000","2,600.000","N","N"};
    QStringList fol2 = {"","C0000208 zhaoxuchang","20230712-HK-5","N","Xyy1","16:22:01","Ask","HK:01288","2.600","1,000.000","2,600.000","N","N"};
    QStringList fol3 = {"","1883002 NGAN, WAN YEUNG","20230712-HK-3","N","admin","16:20:57","Bid","HK:01288","2.600","2,000.000","5,200.000","N","N"};
    QStringList fol4 = {"","1883002 NGAN, WAN YEUNG","20230712-HK-3","N","admin","16:20:57","Bid","HK:01288","2.600","2,000.000","5,200.000","N","N"};
    m_vecFilledOrderListOr3.push_back(fol1);
    m_vecFilledOrderListOr3.push_back(fol2);
    m_vecFilledOrderListOr3.push_back(fol3);
    m_vecFilledOrderListOr3.push_back(fol4);

    QStringList aol1 = {"20230710-HK-25","C0000208","zhaoxuchang","Bid","HK:03011","8,269.000","1","xiu", "\x80\x7B\x53\x4F\x2D\x4E\x87\x65", " "};
    QStringList aol2 = {"20230710-HK-23","C0000208","zhaoxuchang","Bid","HK:03011","8,319.000","1","Xyy1", tr("离价限额(移动端、web)")," "};
    QStringList aol3 = {"20230710-HK-22","C0000208","zhaoxuchang","Bid","HK:03011","8,319.000","1","Xyy1", tr("离价限额(移动端、web)")," "};
    QStringList aol4 = {"20230710-HK-21","C0000208","zhaoxuchang","Bid","HK:03011","8,571.000","1","xiu", tr("离价限额"),"xiu 2023-07-10 17:13:55"};
    QStringList aol5 = {"20230710-HK-19","C0000208","zhaoxuchang","Bid","HK:03011","8,319.000","1","Xyy1",tr("离价限额(移动端、web)"),"xiu 2023-07-10 17:13:49"};
    m_vecApprovedOrderListOr4.push_back(aol1);
    m_vecApprovedOrderListOr4.push_back(aol2);
    m_vecApprovedOrderListOr4.push_back(aol3);
    m_vecApprovedOrderListOr4.push_back(aol4);
    m_vecApprovedOrderListOr4.push_back(aol5);

}


void MainWindow::on_pushButton_clicked()
{
    PDF *p = nullptr;
    float alpha{0.0f};
    time_t timer;
    struct tm ltime;

    p = PDF_new();

    if(p == nullptr || PDF_open_file(p, "pdf_clock.pdf") == -1) {
        qDebug() << "Error: Cannot open PDF file pdfclock.pdf";
        return ;
    }

    PDF_set_info(p, "Creator", "FOM");
    PDF_set_info(p, "Author", "AFI");
    PDF_set_info(p, "Title", "pdf clockf");

    PDF_begin_page(p, (float)(2*(RADIUS+MARGIN)), (float)(2*(RADIUS+MARGIN)));

    PDF_translate(p, RADIUS+MARGIN, RADIUS+MARGIN);

    PDF_setrgbcolor(p, 0.0, 0.0, 1.0);

    PDF_save(p);


    PDF_setlinewidth(p, 2.0);
    for(alpha = 0; alpha < 360; alpha += 6) {
       PDF_rotate(p, 6.0);
       PDF_moveto(p, RADIUS, 0.0);
       PDF_lineto(p, (float)(RADIUS - MARGIN/3), 0.0);
       PDF_stroke(p);
    }
    PDF_restore(p);
    PDF_save(p);

    /* 5 minute strokes */
    PDF_setlinewidth(p, 3.0);
    for (alpha = 0; alpha < 360; alpha += 30)
    {
       PDF_rotate(p, 30.0);
       PDF_moveto(p, RADIUS, 0.0);
       PDF_lineto(p, RADIUS-MARGIN, 0.0);
       PDF_stroke(p);
    }

//    time(&timer);
//    ltime = *localtime(&timer);

//       /* draw hour hand */
//       PDF_save(p);
//       PDF_rotate(p,
//           (float)(-((ltime.tm_min/60.0) + ltime.tm_hour - 3.0) * 30.0));
//       PDF_moveto(p, -RADIUS/10, -RADIUS/20);
//       PDF_lineto(p, RADIUS/2, 0.0);
//       PDF_lineto(p, -RADIUS/10, RADIUS/20);
//       PDF_closepath(p);
//       PDF_fill(p);
//       PDF_restore(p);

//       /* draw minute hand */
//       PDF_save(p);
//       PDF_rotate(p,
//           (float) (-((ltime.tm_sec/60.0) + ltime.tm_min - 15.0) * 6.0));
//       PDF_moveto(p, -RADIUS/10, -RADIUS/20);
//       PDF_lineto(p, RADIUS * 0.8, 0.0);
//       PDF_lineto(p, -RADIUS/10, RADIUS/20);
//       PDF_closepath(p);
//       PDF_fill(p);
//       PDF_restore(p);

//       /* draw second hand */
//       PDF_setrgbcolor(p, 1.0, 0.0, 0.0);
//       PDF_setlinewidth(p, 2);
//       PDF_save(p);
//       PDF_rotate(p, (float) -((ltime.tm_sec - 15.0) * 6.0));
//       PDF_moveto(p, -RADIUS/5, 0.0);
//       PDF_lineto(p, RADIUS, 0.0);
//       PDF_stroke(p);
//       PDF_restore(p);

       /* draw little circle at center */
       PDF_circle(p, 0, 0, (float) RADIUS/30);
       PDF_fill(p);

       PDF_restore(p);

       PDF_end_page(p);

       PDF_close(p);
       PDF_delete(p);

}

bool MainWindow::SetPDFTitle(PDF *p, int orientation, const QString &title, const QString &subTitle, const QString &code) {
    if (nullptr == p) {
        qDebug() << "PDF 指针句柄为空！ \n";
        return false;
    }
    int font = PDF_findfont(p, "Helvetica-Bold", "host", 0);

    if (font == -1) {
        qDebug("Error: Unkown Helvetica-Bold font." );
        return false;
    }
    int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
    if (fontTime == -1) {
        qDebug("Error: Unkown Helvetica font." );
        return false;
    }
    PDF_setfont(p, font, 14);
    float fStringLen = PDF_stringwidth(p,  title.toUtf8().data(), font, 14);
    int width = a4_width, height = a4_height;
    if(orientation == 1) {
         width = width ^ height;
         height = width ^ height;
         width = width ^ height;
    }
    PDF_show_xy(p, title.toUtf8().data(), (width-fStringLen)/2 , height-25);
    fStringLen = PDF_stringwidth(p,  subTitle.toUtf8().data(), font, 14);
     PDF_show_xy(p, subTitle.toUtf8().data(), (width-fStringLen)/2 , height-45);
//    PDF_continue_text(p, subTitle.toUtf8().data());

    PDF_setfont(p, fontTime, 10);
    QDateTime dateTime;
    dateTime = QDateTime::currentDateTime();
    QString sDateTime = dateTime.toString("yyyyMMdd hh:mm:ss");
    qDebug()<<dateTime;
    qDebug() << sDateTime;
    PDF_show_xy(p, sDateTime.toUtf8().data(), width-90 , height-25);
    PDF_continue_text(p, code.toUtf8().data());

    return true;
}

void MainWindow::on_btnAEList_clicked()
{
    PDF *p = nullptr;

    volatile double xt=20, x = 20, y=50, dy=90;

    p = PDF_new();

    if(p == nullptr || PDF_open_file(p, "ae_list.pdf") == -1) {
        qDebug() << "Error: Cannot open PDF file ae_list.pdf";
        return ;
    }

    PDF_set_info(p, "Creator", "FOM");
    PDF_set_info(p, "Author", "AFI");
    PDF_set_info(p, "Title", "pdf ae_list");

    PDF_begin_page(p, a4_width, a4_height);	/* start a new page	*/

    qDebug() <<"a4_width = " << a4_width <<" a4_height =" << a4_height;
//    int font = PDF_findfont(p, "Helvetica-Bold", "host", 0);

//    if (font == -1) {
//        qDebug("Error: Unkown font." );
//        PDF_delete(p);
//               return ;
//    }

//    PDF_setfont(p, font, 14);
    QString sCompName{"WEST BULL Securities Limited"};
//    PDF_show_xy(p, sCompName.toUtf8().data(), a4_width/4 , a4_height-25);
//    PDF_continue_text(p, "AE Listing (Sort By AE Group, AE)");
////    PDF_stroke(p);
    int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
//    PDF_setfont(p, fontTime, 10);
//    QDateTime dateTime;
//    dateTime = QDateTime::currentDateTime();
//    QString sDateTime = dateTime.toString("yyyyMMdd hh:mm:ss");
//    qDebug()<<dateTime;
//    qDebug() << sDateTime;
//    PDF_show_xy(p, sDateTime.toUtf8().data(), a4_width-90 , a4_height-25);
//    PDF_continue_text(p, "AE Code (0103)");

    SetPDFTitle(p, 0, sCompName, "AE Listing (Sort By AE Group, AE)", "AE Code (0103)" );

    /* Table header */
    QString sAECode{"AE Code & Name"};
    QString sGroupCode{"Group Code"};
    QString sStatus{"Status"};
    PDF_show_xy(p, sAECode.toUtf8().data(), x+8 , a4_height-77);
    PDF_show_xy(p, sGroupCode.toUtf8().data(), a4_width - 150 , a4_height-77);
    PDF_show_xy(p, sStatus.toUtf8().data(), a4_width - 60 , a4_height-77);
//    PDF_stroke(p);
    int row = a4_height-95, col = x;

    /* Set the line width */
    PDF_setlinewidth(p, 1.0);

    /*Set the stroke color*/
    PDF_setrgbcolor(p,  0.0, 0.5, 0.5);

    PDF_moveto(p, x, a4_height-80);

    /* Draw a line from the current point to the supplied point */
    PDF_lineto(p, a4_width-x, a4_height-80);

    /* Stroke the path using the current line width and stroke color, and
     * clear it
     */
    PDF_stroke(p);

    PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
    PDF_setfont(p, fontTime, 10);
    int index = 0;
    for (const QStringList& list : m_vecAEList) {
        index = 0;
        for (const QString& str : list) {
            qDebug() << str;
            if(index == 0) col = x+8;
            else if(index == 2) col = a4_width - 150;
            else if(index == 3) col = a4_width - 60;
            else  col = x+60;

            PDF_show_xy(p, str.toUtf8().data(), col , row);
            ++index;
        }
        row -= 13;
    }

    PDF_end_page(p);


    PDF_close(p);

    PDF_delete(p);
}

void MainWindow::orderLogHeader(PDF *p, float x, float & y) {

    QStringList keys1, keys2, keys3, table_title;
    keys1 << "Order NO 107110" << "Buy/Sell S" << "OrderType E" << "Reference F180008";
    keys2 << "Product HKEX 08367 SIMPLICITY HLDG" << "ISIN KYG8072W1087";
    keys3 << "ClientA/C F180008 HUI SUEN TAK" << "Broker Code 1036";
    table_title << "Action" << "Price" << "Qty" << "User" << "Time" << "ExecPrice" << "ExecQty" << "Remark";

//    int y = a4_width-65, x = 20;
    for (const QString& str : keys1) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        x += (a4_height -40) /4;
    }
    y -= 15;
    if(y < 20) {
        PDF_end_page(p);
        PDF_begin_page(p, a4_height, a4_width);
        int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
        if (fontTime == -1) {
            qDebug("Error: Unkown Helvetica font." );
            return ;
        }
        PDF_setfont(p, fontTime, 10);
         y = a4_width-20;
    }
    x = 20;
    for (const QString& str : keys2) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        x += (a4_height -40) /2;
    }
    y -= 15;
    if(y < 20) {
        PDF_end_page(p);
        PDF_begin_page(p, a4_height, a4_width);
        int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
        if (fontTime == -1) {
            qDebug("Error: Unkown Helvetica font." );
            return ;
        }
        PDF_setfont(p, fontTime, 10);
         y = a4_width-20;
    }
    x = 20;
    for (const QString& str : keys3) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        x += (a4_height -40) /2;
    }
    y -= 20;
    if(y < 20) {
        PDF_end_page(p);
        PDF_begin_page(p, a4_height, a4_width);
        int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
        if (fontTime == -1) {
            qDebug("Error: Unkown Helvetica font." );
            return ;
        }
        PDF_setfont(p, fontTime, 10);
         y = a4_width-20;
    }

    x = 20;
    int index = 0;
    for (const QString& str : table_title) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        ++ index;
        if (index == 1) x+= 100;
        if (index == 2) x+= 80;
        if (index == 3) x+= 80;
        if (index == 4) x+= 100;
        if (index == 5) x+= 90;
        if (index == 6) x+= 90;
        if (index == 7) x+= 90;


    }

    /* Set the line width */
    PDF_setlinewidth(p, 1.0);

    /*Set the stroke color*/
    PDF_setrgbcolor(p,  0.0, 0.5, 0.5);

    x = 18;
    y -= 5;
    PDF_moveto(p, x, y);

    /* Draw a line from the current point to the supplied point */
    PDF_lineto(p, a4_height-x, y);

    /* Stroke the path using the current line width and stroke color, and
     * clear it
     */
    PDF_stroke(p);
    if(y < 20) {
        PDF_end_page(p);
        PDF_begin_page(p, a4_height, a4_width);
        int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
        if (fontTime == -1) {
            qDebug("Error: Unkown Helvetica font." );
            return ;
        }
        PDF_setfont(p, fontTime, 10);
         y = a4_width-20;
    }

}

void MainWindow::orderLogContent(PDF *p, const QStringList & list, float x, float & y ) {
    int index = 0;
    for (const QString& str : list) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        ++ index;
        if (index == 1) x+= 100;
        if (index == 2) x+= 80;
        if (index == 3) x+= 80;
        if (index == 4) x+= 100;
        if (index == 5) x+= 90;
        if (index == 6) x+= 90;
        if (index == 7) x+= 90;
    }

}

/*Order Log OR01*/
void MainWindow::on_btnOrderLog_clicked()
{

    PDF *p = nullptr;
    p = PDF_new();

    if(p == nullptr || PDF_open_file(p, "order_log.pdf") == -1) {
        qDebug() << "Error: Cannot open PDF file order_log.pdf";
        return ;
    }

    PDF_set_info(p, "Creator", "FOM");
    PDF_set_info(p, "Author", "AFI");
    PDF_set_info(p, "Title", "pdf ae_list");

    PDF_begin_page(p, a4_height, a4_width);	/* start a new page	*/

    SetPDFTitle(p, 1, "WEST BULL Securities Limited", "Order Log", "AE Code (0103)" );

// ***** begin********

    float y = a4_width-65;
    orderLogHeader(p, 20, y );
    /*Set the stroke color*/
     PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
      y -= 10;
    for (const auto item : m_vecOrderLog) {
        orderLogContent(p, item, 20, y );
        y-=15;
        if(y < 50) {
            PDF_end_page(p);
            PDF_begin_page(p, a4_height, a4_width);
            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
            if (fontTime == -1) {
                qDebug("Error: Unkown Helvetica font." );
                return ;
            }
            PDF_setfont(p, fontTime, 10);
            y = a4_width-20;
        }
    }
    y-=20;

    orderLogHeader(p, 20, y );
    /*Set the stroke color*/
     PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
      y -= 10;
    for (const auto item : m_vecOrderLog) {
        orderLogContent(p, item, 20, y );
        y-=15;
        if(y < 20) {
            PDF_end_page(p);
            PDF_begin_page(p, a4_height, a4_width);
            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
            if (fontTime == -1) {
                qDebug("Error: Unkown Helvetica font." );
                return ;
            }
            PDF_setfont(p, fontTime, 10);
             y = a4_width-20;
        }
    }


    y-=20;
    orderLogHeader(p, 20, y );
    /*Set the stroke color*/
     PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
      y -= 10;
    for (const auto item : m_vecOrderLog) {
        orderLogContent(p, item, 20, y );
        y-=15;
        if(y < 20) {
            PDF_end_page(p);
            PDF_begin_page(p, a4_height, a4_width);
            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
            if (fontTime == -1) {
                qDebug("Error: Unkown Helvetica font." );
                return ;
            }
            PDF_setfont(p, fontTime, 10);
             y = a4_width-20;
        }
    }
    y-=20;


    orderLogHeader(p, 20, y );
    /*Set the stroke color*/
     PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
      y -= 10;
    for (const auto item : m_vecOrderLog) {
        orderLogContent(p, item, 20, y );
        y-=15;
        if(y < 20) {
            PDF_end_page(p);
            PDF_begin_page(p, a4_height, a4_width);
            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
            if (fontTime == -1) {
                qDebug("Error: Unkown Helvetica font." );
                return ;
            }
            PDF_setfont(p, fontTime, 10);
             y = a4_width-20;
        }
    }


    y-=20;
    orderLogHeader(p, 20, y );
    /*Set the stroke color*/
     PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
      y -= 10;
    for (const auto item : m_vecOrderLog) {
        orderLogContent(p, item, 20, y );
        y-=15;
        if(y < 20) {
            PDF_end_page(p);
            PDF_begin_page(p, a4_height, a4_width);
            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
            if (fontTime == -1) {
                qDebug("Error: Unkown Helvetica font." );
                return ;
            }
            PDF_setfont(p, fontTime, 10);
             y = a4_width-20;
        }
    }

     PDF_end_page(p);

     PDF_close(p);

     PDF_delete(p);
}
void MainWindow::orderList02Header(PDF *p, float x, float & y) {

    int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
    if (fontTime == -1) {
        qDebug("Error: Unkown Helvetica font." );
        return ;
    }
    PDF_setfont(p, fontTime, 8);

    QStringList table_title;
    table_title << "ClientA/C" << "AE" << "Product" << "Input User" << "Order No." << "Exch.No.Ref." \
                << "Status" << "B/S" << "Price" << "Qty" << "FilledQty" << "O/S Qty" << "StatusTime***" << "ExtendedTrade";

    x = 20;
    int index = 0;
    for (const QString& str : table_title) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        if (index == 2) x+= 50;
        else if (index == 6 ) x+= 45;
        else if (index == 7) x+= 35;
        else if (index == 12) x+= 70;
        else x += 60;
        ++ index ;
    }

    /* Set the line width */
    PDF_setlinewidth(p, 1.0);

    /*Set the stroke color*/
    PDF_setrgbcolor(p,  0.0, 0.5, 0.5);

    x = 18;
    y -= 5;
    PDF_moveto(p, x, y);

    /* Draw a line from the current point to the supplied point */
    PDF_lineto(p, a4_height-x, y);

    /* Stroke the path using the current line width and stroke color, and
     * clear it
     */
    PDF_stroke(p);
}

void MainWindow::orderListOR2Content(PDF *p, const QStringList & list, float x, float & y) {
    int index = 0;
    int temp_y = y;
    for (const QString& str : list) {
        qDebug() << str;
        if(index == 12 ) {
            QStringList status_time = str.split(',');
            for(const QString &st : status_time) {
                PDF_show_xy(p, st.toUtf8().data(), x , temp_y);
                temp_y -= 15;
            }
        }else {
            PDF_show_xy(p, str.toUtf8().data(), x , y);
        }
        ++ index;
        if (index == 2) x+= 50;
        else if (index == 4 ) x+= 55;
        else if (index == 5 ) x+= 70;
        else if (index == 6 ) x+= 55;
        else if (index == 7) x+= 45;
        else if (index == 8) x+= 35;
        else if (index == 12) x+= 70;
        else if (index == 13) x+= 75;
        else x += 60;
    }
    y = temp_y;
}

void MainWindow::on_btnOrderList02_clicked()
{
    PDF *p = nullptr;
    p = PDF_new();

    if(p == nullptr || PDF_open_file(p, "order_list_OR02.pdf") == -1) {
        qDebug() << "Error: Cannot open PDF file order_log.pdf";
        return ;
    }

    PDF_set_info(p, "Creator", "FOM");
    PDF_set_info(p, "Author", "AFI");
    PDF_set_info(p, "Title", "pdf order_list");

    PDF_begin_page(p, a4_height, a4_width);	/* start a new page	*/

    SetPDFTitle(p, 1, "WEST BULL Securities Limited", "Order Listing", "AE Code (0103)" );

    float y = a4_width-65;
    orderList02Header(p, 20, y );
    PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
    y -= 10;

    for (const auto item : m_vecOrderListOr2) {

        if(y < 20) {
            PDF_end_page(p);
            PDF_begin_page(p, a4_height, a4_width);
            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
            if (fontTime == -1) {
                qDebug("Error: Unkown Helvetica font." );
                return ;
            }
            PDF_setfont(p, fontTime, 8);
            y = a4_width-20;
            orderList02Header(p, 20, y );
            PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
            y -= 10;
        }
        orderListOR2Content(p, item, 20, y );
        y-=15;
    }

    PDF_end_page(p);

    PDF_close(p);

    PDF_delete(p);
}
void MainWindow::filledOrderList03Header(PDF *p, float x, float & y) {

    int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
    if (fontTime == -1) {
        qDebug("Error: Unkown Helvetica font." );
        return ;
    }
    PDF_setfont(p, fontTime, 8);

    QStringList table_title;
    table_title << "AE" << "Client A/C" << "Order No." << "Ref/Routing" \
                << "User" << "Time" << "B/S" << "Product" << "Price" << "Qty" << "Amount" << "ExtendedTrade" << "ForceSell";

    x = 20;
    int index = 0;
    for (const QString& str : table_title) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        if (index == 0) x+= 50;
        else if (index == 1 ) x+= 120;  // "Client A/C"
        else if (index == 5 ) x+= 45; // "B/S"
        else if (index == 6) x+= 35;
        else if (index == 12) x+= 70;
        else x += 60;

        ++ index ;
    }

    /* Set the line width */
    PDF_setlinewidth(p, 1.0);

    /*Set the stroke color*/
    PDF_setrgbcolor(p,  0.0, 0.5, 0.5);

    x = 18;
    y -= 5;
    PDF_moveto(p, x, y);

    /* Draw a line from the current point to the supplied point */
    PDF_lineto(p, a4_height-x, y);

    /* Stroke the path using the current line width and stroke color, and
     * clear it
     */
    PDF_stroke(p);
}


void MainWindow::filledOrderListOR3Content(PDF *p, const QStringList & list, float x, float & y) {
    int index = 0;
    for (const QString& str : list) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        if (index == 0) x+= 50;
        else if (index == 1 ) x+= 120;  // "Client A/C"
        else if (index == 5 ) x+= 45; // "B/S"
        else if (index == 6) x+= 35;
        else if (index == 12) x+= 70;
        else x += 60;
        ++ index;
    }
}

void MainWindow::filledOrderListOR03Totol(PDF *p, const QString &list, float y) {

    /* Set the line width */
    PDF_setlinewidth(p, 1.0);

    /*Set the stroke color*/
    PDF_setrgbcolor(p,  0.0, 0.5, 0.5);

//    float x = 180;
    y -= 5;
    PDF_moveto(p, a4_height/2 + 100, y);

    /* Draw a line from the current point to the supplied point */
    PDF_lineto(p, a4_height-20, y);

    /* Stroke the path using the current line width and stroke color, and
     * clear it
     */
    PDF_stroke(p);
    PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
    y -= 13;
    PDF_show_xy(p, list.toUtf8().data(), a4_height/2+120 , y);

}
void MainWindow::on_btnFilledOrderList03_clicked()
{
    PDF *p = nullptr;
    p = PDF_new();

    if(p == nullptr || PDF_open_file(p, "filled_orders_isting_OR03.pdf") == -1) {
        qDebug() << "Error: Cannot open PDF file order_log.pdf";
        return ;
    }

    PDF_set_info(p, "Creator", "FOM");
    PDF_set_info(p, "Author", "AFI");
    PDF_set_info(p, "Title", "Filled Orders Listing");

    PDF_begin_page(p, a4_height, a4_width);	/* start a new page	*/

    SetPDFTitle(p, 1, "WEST BULL Securities Limited", "Filled Orders Listing", "AE Code (0103)" );

    float y = a4_width-65;
    filledOrderList03Header(p, 20, y );
    PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
    y -= 10;
    for (const auto item : m_vecFilledOrderListOr3) {

        if(y < 20) {
            PDF_end_page(p);
            PDF_begin_page(p, a4_height, a4_width);
            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
            if (fontTime == -1) {
                qDebug("Error: Unkown Helvetica font." );
                return ;
            }
            PDF_setfont(p, fontTime, 8);
            y = a4_width-20;
            filledOrderList03Header(p, 20, y );
            PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
            y -= 10;
        }
        filledOrderListOR3Content(p, item, 20, y );
        y-=15;

    }
    QString str{""};
     filledOrderListOR03Totol(p, "Grand Total:    3 Order(s)     Amt    10400",y);

    PDF_end_page(p);

    PDF_close(p);

    PDF_delete(p);
}

// Approved Order list OR04

void MainWindow::approvedRejectedOrderListHeader(PDF *p, float x, float & y, bool type) {

    int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
    if (fontTime == -1) {
        qDebug("Error: Unkown Helvetica font." );
        return ;
    }
    PDF_setfont(p, fontTime, 8);

    QStringList table_title;
    if (type) {
        table_title << "Order No." << "Client a/c" << "Client Name" << "B/S" << "Product" << "Price" \
                << "Quantity" << "Input User" << "Limit Code Reason" << "Approved User&Time";
    } else {
        table_title << "Order No." << "Client a/c" << "Client Name" << "B/S" << "Product" << "Price" \
                    << "Quantity" << "Input User" << "Limit Code Reason" << "Reject User&Time";
    }

    x = 20;
    int index = 0;
    for (const QString& str : table_title) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        if (index == 0) x+= 80;
        else if (index == 2 ) x+= 120;  // "Client A/C"
        else if (index == 3 ) x+= 45; // "B/S"
//        else if (index == 4) x+= 95;
         else if (index == 8) x+= 125;
        else x += 60;

        ++ index ;
    }

    /* Set the line width */
    PDF_setlinewidth(p, 1.0);

    /*Set the stroke color*/
    PDF_setrgbcolor(p,  0.0, 0.5, 0.5);

    x = 18;
    y -= 5;
    PDF_moveto(p, x, y);

    /* Draw a line from the current point to the supplied point */
    PDF_lineto(p, a4_height-x, y);

    /* Stroke the path using the current line width and stroke color, and
     * clear it
     */
    PDF_stroke(p);
}


void MainWindow::approvedRejectedOrderListContent(PDF *p, const QStringList & list, float x, float & y) {
        int index = 0;
        for (const QString& str : list) {
            qDebug() << str.toUtf8().constData();

            PDF_show_xy(p,  str.toUtf8().constData(), x , y);
            if (index == 0) x+= 80;
            else if (index == 2 ) x+= 120;  // "Client A/C"
            else if (index == 3 ) x+= 45; // "B/S"
//            else if (index == 4) x+= 95;
            else if (index == 8) x+= 125;
            else x += 60;
            ++ index;
        }
    }

void MainWindow::on_btnApporedOrderList_clicked()
{
    PDF *p = nullptr;
    p = PDF_new();

    if(p == nullptr || PDF_open_file(p, "approved_order_listing_OR04.pdf") == -1) {
        qDebug() << "Error: Cannot open PDF file order_log.pdf";
        return ;
    }

    PDF_set_info(p, "Creator", "FOM");
    PDF_set_info(p, "Author", "AFI");
    PDF_set_info(p, "Title", "Approved Orders Listing");

    PDF_begin_page(p, a4_height, a4_width);	/* start a new page	*/

    SetPDFTitle(p, 1, "WEST BULL Securities Limited", "Approved Order Listing", "AE Code (0103)" );

    float y = a4_width-65;
    approvedRejectedOrderListHeader(p, 20, y, true);

    PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
    y -= 10;
    for (const auto item : m_vecApprovedOrderListOr4) {

        if(y < 20) {
            PDF_end_page(p);
            PDF_begin_page(p, a4_height, a4_width);
            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
            if (fontTime == -1) {
                qDebug("Error: Unkown Helvetica font." );
                return ;
            }
            PDF_setfont(p, fontTime, 8);
            y = a4_width-20;
            approvedRejectedOrderListHeader(p, 20, y, true);
            PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
            y -= 10;
        }
        approvedRejectedOrderListContent(p, item, 20, y );
        y-=15;

    }


    PDF_end_page(p);

    PDF_close(p);

    PDF_delete(p);
}

/**
 * @brief Reject Order List OR05
 */
void MainWindow::on_btnRejectOrderList05_clicked()
{
    PDF *p = nullptr;
    p = PDF_new();

    if(p == nullptr || PDF_open_file(p, "Rejected_Order_Listing_OR05.pdf") == -1) {
        qDebug() << "Error: Cannot open PDF file order_log.pdf";
        return ;
    }

    PDF_set_info(p, "Creator", "FOM");
    PDF_set_info(p, "Author", "AFI");
    PDF_set_info(p, "Title", "Rejected Orders Listing");
    PDF_begin_page(p, a4_height, a4_width);	/* start a new page	*/

    SetPDFTitle(p, 1, "WEST BULL Securities Limited", "Rejected Order (By Credit Officer) Listing ", "AE Code (0103)" );

    float y = a4_width-65;
    approvedRejectedOrderListHeader(p, 20, y, false);

    PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
    y -= 10;
    for (const auto item : m_vecApprovedOrderListOr4) {

        if(y < 20) {
            PDF_end_page(p);
            PDF_begin_page(p, a4_height, a4_width);
            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
            if (fontTime == -1) {
                qDebug("Error: Unkown Helvetica font." );
                return ;
            }
            PDF_setfont(p, fontTime, 8);
            y = a4_width-20;
            approvedRejectedOrderListHeader(p, 20, y, false);
            PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
            y -= 10;
        }
        approvedRejectedOrderListContent(p, item, 20, y );
        y-=15;

    }

    PDF_end_page(p);

    PDF_close(p);

    PDF_delete(p);
}

/**
 * @brief OrderDetailsList06
 */
void MainWindow::orderDetailsList06Header(PDF *p, float x, float & y) {

    int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
    if (fontTime == -1) {
        qDebug("Error: Unkown Helvetica font." );
        return ;
    }
    PDF_setfont(p, fontTime, 8);

    QStringList table_title;
    table_title << "Client a/c" << "AE" << "Product" << "Order No." << "Status" << "Chan." << "B/S" << "Qty" << "Fill Qty" << "Price" \
                << "Fill Time" << "Brk" << "User Actions" << "User" << "Time" << "Extended Trade";
    x = 20;
    int index = 0;
    for (const QString& str : table_title) {
        qDebug() << str;
        PDF_show_xy(p, str.toUtf8().data(), x , y);
        if (index == 0) x+= 50;
        else if (index == 1 ) x+= 50;  // "Client A/C"
        else if (index == 3 ) x+= 45;
        else if (index == 4) x+= 35;
        else if (index == 5) x+= 35;  // "B/S"
         else if (index == 11) x+= 35;
        else if (index == 12) x+= 65;
        else if (index == 14) x+= 75;
        else x += 50;
    str.split(',');
        ++ index ;
    }

    /* Set the line width */
    PDF_setlinewidth(p, 1.0);

    /*Set the stroke color*/
    PDF_setrgbcolor(p,  0.0, 0.5, 0.5);

    x = 18;
    y -= 5;
    PDF_moveto(p, x, y);

    /* Draw a line from the current point to the supplied point */
    PDF_lineto(p, a4_height-x, y);

    /* Stroke the path using the current line width and stroke color, and
     * clear it
     */
    PDF_stroke(p);
}


void MainWindow::on_btnOrderDetailsList06_clicked()
{
    PDF *p = nullptr;
    p = PDF_new();

    if(p == nullptr || PDF_open_file(p, "order_details_listing_OR06.pdf") == -1) {
        qDebug() << "Error: Cannot open PDF file order_log.pdf";
        return ;
    }

    PDF_set_info(p, "Creator", "FOM");
    PDF_set_info(p, "Author", "AFI");
    PDF_set_info(p, "Title", "Approved Orders Listing");

    PDF_begin_page(p, a4_height, a4_width);	/* start a new page	*/

    SetPDFTitle(p, 1, "WEST BULL Securities Limited", "Order Details Listing", "AE Code (0103)" );

    float y = a4_width-65;
    orderDetailsList06Header(p, 20, y);

    PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
    y -= 10;
//    for (const auto item : m_vecApprovedOrderListOr4) {

//        if(y < 20) {
//            PDF_end_page(p);
//            PDF_begin_page(p, a4_height, a4_width);
//            int fontTime = PDF_findfont(p, "Helvetica", "host", 0);
//            if (fontTime == -1) {
//                qDebug("Error: Unkown Helvetica font." );
//                return ;
//            }
//            PDF_setfont(p, fontTime, 8);
//            y = a4_width-20;
//            approvedRejectedOrderListHeader(p, 20, y, true);
//            PDF_setrgbcolor(p,  0.0, 0.0, 0.1);
//            y -= 10;
//        }
//        approvedRejectedOrderListContent(p, item, 20, y );
//        y-=15;

//    }


    PDF_end_page(p);

    PDF_close(p);

    PDF_delete(p);
}

void MainWindow::on_btnUserListing_clicked()
{

}



















#include <QPdfWriter>
#include <QPainter>
#include <QDesktopServices>
 #include <QFile>
#include <QUrl>

void MainWindow::pdfDrawForm(QPainter *paint, int y, int horzBorder, int row, int column, int unitHeight, QFont &font, QStringList &list)
{
    paint->setFont(font);

    paint->setPen(QPen(QBrush(QColor(0, 0, 0)), 2));

    int Width = paint->viewport().width() - horzBorder * 2;

    int unitWidth = Width / column;

    for(int i=0;i<row;i++) {
        int x = horzBorder;

        for(int j=0;j<column;j++) {
            paint->drawText(QRect(x, y, unitWidth, unitHeight), Qt::AlignCenter, list[i*column + j]);
            paint->drawRect(QRect(x, y, unitWidth, unitHeight));
            x += unitWidth;
        }

        y += unitHeight;
    }
}











void MainWindow::on_pushButton_2_clicked()
{
    //创建PDF文件
    QString file_path = QApplication::applicationDirPath() + "/text.pdf";

    QFile pdfFile(file_path);
    pdfFile.open(QIODevice::WriteOnly);
    QPdfWriter *pWriter = new QPdfWriter(&pdfFile);

    pWriter->setPageSize(QPagedPaintDevice::A4);
    pWriter->setResolution(300);
    pWriter->setPageMargins(QMarginsF(30, 30, 30, 30));

    QPainter *pPainter = new QPainter(pWriter);

    QFont font[5] = {QFont("宋体", 26, 60), QFont("宋体", 26, 61), QFont("宋体", 26, QFont::Normal), QFont("宋体", 26, QFont::Normal), QFont("宋体", 26, QFont::Normal)};
    font[0].setPixelSize(86);
    font[1].setPixelSize(61);
    font[2].setPixelSize(61);
    font[3].setPixelSize(42);
    font[4].setPixelSize(54);

    qDebug()<<pPainter->viewport().width()<<" "<<pPainter->viewport().height();

    int nPDFWidth = pPainter->viewport().width();
    int nPDFHeight = pPainter->viewport().height();

    //标题
    int y = 10;
    pPainter->setFont(font[0]);
    pPainter->drawText(QRect(0, y, nPDFWidth, 100), Qt::AlignCenter, QString("这是第一个PDF文档"));
    //画两条横线
    y += 140;
    pPainter->setPen(QPen(QBrush(QColor(0, 0, 0)), 5));
    pPainter->drawLine(0, y, nPDFWidth, y);
    pPainter->drawLine(0, y + 18, nPDFWidth, y + 18);
    //添加文字
    y += 60;
    pPainter->setFont(font[2]);
    pPainter->drawText(QRect(100, y, nPDFWidth/2, 70), Qt::AlignVCenter | Qt::AlignLeft, QString("器件型号: YT-CR810"));
    pPainter->setFont(font[2]);
    pPainter->drawText(QRect(nPDFWidth/2 + 100 , y, nPDFWidth/2 - 100, 70), Qt::AlignVCenter | Qt::AlignLeft, QString("器件编号: YT-CR810"));

    y += 90;
    pPainter->setFont(font[2]);
    pPainter->drawText(QRect(100, y, nPDFWidth/2, 70), Qt::AlignVCenter | Qt::AlignLeft, QString("装车车号: YT-CR810"));
    pPainter->setFont(font[2]);
    pPainter->drawText(QRect(nPDFWidth/2 + 100 , y, nPDFWidth/2 - 100, 70), Qt::AlignVCenter | Qt::AlignLeft, QString("实验日期: YT-CR810"));
    //小标题
    y += 110;
    pPainter->setFont(font[1]);
    pPainter->drawText(QRect(0, y, nPDFWidth, 80), Qt::AlignVCenter | Qt::AlignLeft, "减 振 器 标 准 参 数");
    //画表格
    y += 120;
    QStringList list;
    list<<"速度"<<"压力"<<"拉力"<<"阻尼系数"<<"不对称率"<<"正允差"<<"负允差";
    list<<"12.5m/s"<<"17KN"<<"15KN"<<"1.3kNs/m"<<"12%"<<"13%"<<"14%";
    pdfDrawForm(pPainter, y, 0, 2, 7, 100, font[3], list);

    y += 260;
    pPainter->setFont(font[1]);
    pPainter->drawText(QRect(0, y, nPDFWidth, 80), Qt::AlignVCenter | Qt::AlignLeft, "示功图");
    //插入图片
    y += 100;
    int imageBorder = 150;
    QPixmap pixmap = QPixmap::grabWidget(this, this->rect());
    float x = (float)(nPDFWidth - imageBorder * 2) / (float)pixmap.width();
    pixmap = pixmap.scaled(nPDFWidth - imageBorder * 2, x * pixmap.height(), Qt::IgnoreAspectRatio);
    pPainter->drawPixmap(imageBorder, y, pixmap);

    y += pixmap.height() + 90;
    pPainter->setFont(font[1]);
    pPainter->drawText(QRect(0, y, nPDFWidth, 80), Qt::AlignVCenter | Qt::AlignLeft, "减 震 器 测 试 结 果");

    y += 120;
    list.clear();
    list<<"拉伸行程"<<"0.00mm"<<"压缩行程"<<"0.00mm"<<"最大速度"<<"0.000m/s"<<"阻尼系数"<<"0.00kNs/m"
       <<"最大压力"<<"0.00kN"<<"压力偏差"<<"0.00%"<<"最大拉力"<<"0.00kN"<<"拉力偏差"<<"0.00%"
      <<"不对称率"<<"0.00%"<<"运动时间"<<"5S"<<"实验结果"<<"100%"<<"曲线结论"<<"100";
    pdfDrawForm(pPainter, y, 0, 3, 8, 100, font[3], list);

    pPainter->setFont(font[4]);
    pPainter->drawText(QRect(50, nPDFHeight, nPDFWidth/3, 80), Qt::AlignVCenter | Qt::AlignLeft, QString( "试验员: 张三"));
    pPainter->drawText(QRect(nPDFWidth/3+50, nPDFHeight, nPDFWidth/3, 80), Qt::AlignVCenter | Qt::AlignLeft, QString( "检查员签字: "));
    pPainter->drawText(QRect(nPDFWidth/3*2, nPDFHeight, nPDFWidth/3, 80), Qt::AlignVCenter | Qt::AlignLeft, QString( "签字日期: "));

    //绘制完毕
    delete pPainter;
    delete pWriter;
    pdfFile.close();

    //通过其他PDF阅读器来打开PDF
    QDesktopServices::openUrl(QUrl::fromLocalFile(file_path));
}
